package com.jinzecloud.reportapproval.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.jinzecloud.reportapproval.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jinzecloud.reportapproval.bean.Product;
import com.jinzecloud.reportapproval.service.ProductService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;



/**
 * 产品表
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-12-03 16:18:45
 */
@RestController
@RequestMapping("reportapproval/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("reportapproval:product:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 获取项目编号
     */
    @RequestMapping("/getProjectNumber")
    //@RequiresPermissions("reportapproval:product:list")
    public R getProjectNumber(){
        List<Product> productList = productService.getProjectNumber();
        return R.ok().put("productList", productList);
    }

    /**
     * 根据id获取产品信息
     */
    @RequestMapping("/info/{prId}")
    //@RequiresPermissions("reportapproval:product:list")
    public R info(@PathVariable ("prId") Integer prId){
        ProductVo product = productService.getByIdProductVo(prId);
        return R.ok().put("product", product);
    }

    /**
     * 根据id获取产品信息
     */
    @RequestMapping("/getCover/{productNumber}")
    //@RequiresPermissions("reportapproval:product:list")
    public R getCover(@PathVariable ("productNumber") String productNumber){
        ProductVo product = productService.getCover(productNumber);
        return R.ok().put("product", product);
    }


    /**
     * 根据编号获取产品信息
     */
    @RequestMapping("/getProductInfo/{productNumber}")
    //@RequiresPermissions("reportapproval:product:list")
    public R getProductInfo(@PathVariable("productNumber") String productNumber){
        Product product = productService.getProductInfo(productNumber);
        return R.ok().put("productInfo", product);
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("reportapproval:product:save")
    public R save(@RequestBody ProductVo productVo){
		R r = productService.saveProduct(productVo);

        return r;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("reportapproval:product:update")
    public R update(@RequestBody ProductVo productVo){
		productService.updateByIdProduct(productVo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("reportapproval:product:delete")
    public R delete(@RequestBody Integer[] prIds){
		productService.removeByIds(Arrays.asList(prIds));

        return R.ok();
    }

}
